//
//  Button.swift
//  myhub
//
//  Created by x on 2024/3/5.
//

import UIKit
import XDesignKit

open class Button: UIButton {
    override public init(frame: CGRect) {
        super.init(frame: frame)
        makeUI()
    }

    public required init?(coder: NSCoder) {
        super.init(coder: coder)
        makeUI()
    }

    open func makeUI() {
        theme.backgroundImage(from: themeService.attribute { $0.secondary }, for: .normal)
        theme.backgroundImage(from: themeService.attribute { $0.secondary.withAlphaComponent(0.9) }, for: .selected)
        theme.backgroundImage(from: themeService.attribute { $0.secondary.withAlphaComponent(0.6) }, for: .disabled)

        layer.masksToBounds = true
        titleLabel?.lineBreakMode = .byWordWrapping
        cornerRadius = Dimensions.cornerRadius

        snp.makeConstraints { make in
            make.height.equalTo(Dimensions.buttonHeight)
        }
        updateUI()
    }

    open func updateUI() {
        setNeedsDisplay()
    }
}
